//certificate_query.js @author zlx
const app = getApp()
Page({
  data: {
    StatusBar: app.globalData.StatusBar,
    CustomBar: app.globalData.CustomBar,
    checked:true,
    //搜索条件
    certificate: {
      certType: '',
      certId: '',
      projectName: '',
      certUnit: '',
      beginDate: '',
      endDate: '',
    },
    certTypeList: [],
    //证书类型是否已选择
    certTypeSelect: false,
    //部门选择第几个
    certTypeIndex: 0,
    beginDateIsSelect: false,
    //终止日期是否已选择
    endDateIsSelect: false,
  },

  onLoad: function (options) {
    this.setData({
      userInfo: wx.getStorageSync('userInfo'),
      certTypeList: wx.getStorageSync('baseData')['3']
    })
  },

  onReady: function () {

  },

  onShow: function () {

  },

  onHide: function () {

  },

  onUnload: function () {

  },

  onPullDownRefresh: function () {
    wx.showNavigationBarLoading() //在标题栏中显示加载
    this.clearQueryCondition()
    wx.hideNavigationBarLoading() //完成停止加载
    wx.stopPullDownRefresh()
  },

  onReachBottom: function () {

  },

  // onShareAppMessage: function () {

  // },

  //证书类型选择
  bindCertTypePickerChange: function (e) {
    // console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      certTypeIsSelect: true,
      certTypeIndex: e.detail.value,
    })
    this.setData({
      'certificate.certType': this.data.certTypeList[this.data.certTypeIndex].codeDetail
    })
    // console.log(this.data.certificate)
  },

  bindCertIdInput: function (e) {
    this.setData({
      'certificate.certId': e.detail.value
    })
    // console.log(this.data.certificate)
  },

  bindProjectNameInput: function (e) {
    this.setData({
      'certificate.projectName': e.detail.value
    })
    // console.log(this.data.certificate)
  },

  bindCertUnitInput: function (e) {
    this.setData({
      'certificate.certUnit': e.detail.value
    })
    // console.log(this.data.certificate)
  },

  //起始日期选择
  bindBeginDateChange: function (e) {
    // console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      beginDateIsSelect: true,
      'certificate.beginDate': e.detail.value
    })
  },

  //终止日期选择
  bindEndDateChange: function (e) {
    // console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      endDateIsSelect: true,
      'certificate.endDate': e.detail.value
    })
  },

  clearQueryCondition: function () {
    this.setData({
      'certificate.certType': '',
      certTypeIsSelect: false,
      'certificate.certId': '',
      'certificate.projectName': '',
      'certificate.certUnit': '',
      'certificate.beginDate': '',
      beginDateIsSelect: false,
      'certificate.endDate': '',
      endDateIsSelect: false
    })
  },

  goCertificateList: function () {
    if (this.data.certificate.beginDate && this.data.certificate.endDate && this.data.certificate.beginDate > this.data.certificate.endDate) {
      wx.showModal({
        title: '系统提示',
        content: '到期日期不能大于发证日期',
        showCancel: false,
        success(res) {
          if (res.confirm) {} else if (res.cancel) {}
        }
      })
      return
    }

    wx.navigateTo({
      url: '/pages/certificate/certificate_filter/certificate_list?cert_type=' + this.data.certificate.certType + '&cert_id=' + this.data.certificate.certId + '&project_name=' + this.data.certificate.projectName + '&cert_unit=' + this.data.certificate.certUnit + '&begin_date=' + this.data.certificate.beginDate + '&end_date=' + this.data.certificate.endDate+'&title='+'查询证书列表'+'&type=1'
    })
  },

})